package com.design.pattern.proxy;

/**
 * @Projectname: design-pattern
 * @Filename: ProxySubject
 * @Author: FANSEA
 * @Date:2024/11/4 10:58
 */
public class ProxySubject implements Subject{
    Subject subject;

    public ProxySubject()  {
        try{
            subject = (Subject) this.getClass().getClassLoader().loadClass("com.design.pattern.proxy.RealSubject").newInstance();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    @Override
    public void request() {
        this.preRequest();
        subject.request();
        this.afterRequest();
    }

    @Override
    public void response() {
        subject.response();
    }

    public void preRequest() {
        System.out.println("连接数据库成功！");
    }
    public void afterRequest() {
        System.out.println("释放连接！");
    }
}
